package com.sch.study.pattern;

import java.util.concurrent.BlockingQueue;

/**
 * User: hui_stone
 * Date: 2015/2/20 0020
 * Time: 下午 13:58
 */
public class Consume implements Runnable{

    private BlockingQueue<Food> foods;

    Consume(BlockingQueue<Food> foods){
        this.foods = foods;
    }
    @Override
    public void run() {
        try {
            Thread.sleep(1000);  //用于测试当生产者生产满10个食品后是否进入等待状态
            while (true){
                //当容器里面的食品数量为空时，那么在while里面该食品容器(阻塞队列)会自动阻塞  wait状态 等待生产
                Food food = foods.take();
                System.out.println("消费"+food.getName());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

}
